import numpy as np
a1 = np.array([12,23,34])
a2 = np.array([
    [12,23,34],
    [132,23,34],
    [2,3,56]]
)
# print('dim:',a1.ndim)
# print('shape:',a1.shape)
# print('size:',a1.size)

# 创建矩阵
a3 = np.array([1,2,3],dtype=np.int64)
# print(a3.dtype)
a4 = np.array([1,2,3],dtype=np.float64)
# print(a4.dtype)
# print(a4)
azero = np.zeros((3,4),dtype=np.int64)
# print(azero)
aone= np.ones((3,4))
# print(aone)

#在一定的范围 (10,22) 步长为 1  [10 11 12 13 14 15 16 17 18 19 20 21]
a = np.arange(10,22,1)
# print(a)
# 重构 shape
a = a.reshape((3,4))
# print(a)
# 均分构建  在(1,10) 平分成 5 段
a = np.linspace(1,10,6).reshape(2,3)
# print('a = ',a)

# 数组的减法
a = np.array([5,6,7,8])
b = np.arange(4)  # 1,2,3,4
# print('a -b=',a - b)
# print('a + b=',a + b)
# print('a^2',a**2)
# # 条件筛选 a 里面的元素大于 6 的
# print(a > 6) #[False False  True  True]

# 矩阵的运算
a = np.array([[6,7],
              [8,9]])
b = np.array([1,2,3,4]).reshape((2,2))
# print(a)
# print(b)
# print('a*b\n',a*b)
# print('a dot b\n',a.dot(b))



#  最值
a = np.arange(-1,11).reshape(3,4)
# print('a = \n',a)
# # 返回下标
# print('max = ',np.argmax(a))
# print('min = ',np.argmin(a))
# #平均值
# print('avg = ',np.mean(a))
# median
# print('median = ',np.median(a))
# 累加   [ 2  5  9 14 20 27 35 44 54 65 77 90]
# print(np.cumsum(a))
# 累差
# print(np.diff(a))

# 求非零元素
# print(np.nonzero(a))
#转置
# print(a.T)

# 截取  <5 的数改为 5   大于 9 的数改为 9
# print(np.clip(a,5,9))

# aixs = 0对于列进行计算
a = np.array([
    [5,98,12],
    [67,23,18],
    [87,45,37]
])
# print('max = ',np.argmax(a,axis=0))




##### 按照索引输出
a = np.array([
    [5,98,12],
    [67,23,18],
    [87,45,37]
])

print(a[0])
print(a[0][0])
print(a[0,0])

# 第一行所有数
print(a[1,:])
# 第一行 0-1 列
print(a[1,0:2])
# 第一列所有数
print(a[:,1],'\n')

#  迭代行
for row in a:
    print(row)

#  迭代列
for col in a.T:
    print(col)
print(a.flatten())
#  迭代个体
for col in a.flat:
    print(col)